package com.jsrj.controller;

import com.jsrj.utils.Qqq;
import com.jsrj.common.annotation.Log;
import com.jsrj.common.core.controller.BaseController;
import com.jsrj.common.core.domain.AjaxResult;
import com.jsrj.common.core.page.TableDataInfo;
import com.jsrj.common.enums.BusinessType;
import com.jsrj.common.utils.poi.ExcelUtil;
import com.jsrj.domain.Shop;
import com.jsrj.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-09-03
 */
@RestController
@RequestMapping("/system/shop")
public class ShopController extends BaseController
{
    @Autowired
    private IShopService shopService;
    @Autowired
    Qqq qe;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shop shop)
    {
        startPage();
        List<Shop> list = shopService.selectShopList(shop);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shop shop)
    {
        List<Shop> list = shopService.selectShopList(shop);
        ExcelUtil<Shop> util = new ExcelUtil<Shop>(Shop.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return AjaxResult.success(shopService.selectShopByShopId(shopId));
    }


    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:shop:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(shopService.deleteShopByShopIds(shopIds));
    }


    @GetMapping("/queryAll")
    public AjaxResult queryAll(){
        return AjaxResult.success(shopService.queryAll());
    }



    @PostMapping("/insert")
    public AjaxResult insertShop(@RequestBody Shop shop){

        shop.setShopInserterTime(new Date());
        shopService.insertByShop(shop);
        return AjaxResult.success(shop.getShopId());
    }


    @PostMapping("/update")
    public AjaxResult updateShop(@RequestBody Shop shop){
        shop.setShopInserterTime(new Date());
        return AjaxResult.success(shopService.updateByShopId(shop));
    }


    @GetMapping("/delete")
    public AjaxResult deleteShop(@RequestParam Long shopId){
        return AjaxResult.success(shopService.deleteByShopId(shopId));
    }

}
